Repository navigation
Fix PXI I2C size decode - #976
Conversation
| if (size >= SHMEM_BUFFER_SIZE) | ||
| return false; | ||
| if (size > 0x7FFF) | ||
| return false; |
There was a problem hiding this comment.
I'd rather see something like _Static_assert(SHMEM_BUFFER_SIZE < BIT(15)); rather than the two runtime checks here, but other than that it looks perfect
the "proper" way to fix it would be to define some types in shmem.h that describe the bitfield layout but that might be a bit too many changes, I'd rather have this as it's only used once or twice
There was a problem hiding this comment.
Wouldn't this potentially not work correctly?
if SHMEM_BUFFER_SIZE is 2048 (current value) and you try to read/write 4096 bytes, then nothing will stop that with a static assert of SHMEM_BUFFER_SIZE < BIT(31)
|
Thanks for the debug and fix, was a really stupid mistake on my part! (also sorry for the delay lol) |
|
@Wolfvak I was a bit slow on this (sorry), I was planning on making one more commit to it. Did you read my last comment? |
|
Yes, I consider this to be "not worse than before" and there's still a bugfix included, so I didn't consider the Feel free to open another PR that adds that check, at your own pace |
During some testing I discovered changing SHMEM_BUFFER_SIZE from
2048to20480broke I2C transfers.This was due to size not being calculated correctly.
Test code:
This was tested using onlinegdb.com:
Output of the test code with
sizeset to22:Old size: 12310, New size: 22The second commit adds a 15-bit size check to the arm9 side, rejecting commands early if size is too big.